<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>管理员配置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="//cdn.staticfile.org/layui/2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        body {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" lay-filter="account-info">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form">
                <blockquote class="layui-elem-quote">管理员配置</blockquote>
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名:</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" class="layui-input"
                               lay-verify="required"
                               lay-reqtext="用户名不能为空">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">旧密码:</label>
                    <div class="layui-input-block">
                        <input type="password" name="oldpwd" placeholder="请输入当前的管理员密码" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">新密码:</label>
                    <div class="layui-input-block">
                        <input type="password" name="newpwd" placeholder="不修改请留空" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">重输密码:</label>
                    <div class="layui-input-block">
                        <input type="password" name="newpwd2" placeholder="不修改请留空" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn " lay-submit lay-filter="saveBtn">确认修改</button>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
<script type="text/html" id="template_tpl">
    {{#for(const item of d){}}
    <option value="{{item}}">{{item}}</option>
    {{# }}}
</script>
<script src="//cdn.staticfile.org/layui/2.6.3/layui.js" charset="utf-8"></script>
<script src="../js/common.js" charset="utf-8"></script>
<script src="../js/api.js" charset="utf-8"></script>
<script>

    const init = () => {
        //layer.load(1)
        httpGet('/admin/system/get?key=admin_username').then(res => {
            if (res.status === 'ok') {
                layui.form.val('account-info', {'username' : res.data})
            }
        })
    }
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            laytpl = layui.laytpl,
            $ = layui.$;
        init();

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            layer.load(1)
            httpPost('/admin/system/setpwd', data.field).then(res => {
                if (res.status === 'ok') {
                    $message.success('修改成功');
                }
            }).finally(() => {
                layer.closeAll('loading')
            })
            return false;
        });

    });
</script>
</body>
</html>